//
//  WHBankNameHelper.m
//  LvZhongMagicKey
//
//  Created by 邓伟浩 on 2018/1/23.
//  Copyright © 2018年 邓伟浩. All rights reserved.
//

#import "WHBankNameHelper.h"

@implementation WHBankNameHelper

NSString *GetBankName(WHBankName status) {
    switch (status) {
        case WHBankNameIllegal:
            return @"卡号不合法";
        case WHBankNameUnknow:
            return @"未知卡号";
        case WHBankNameValid:
            return @"合法";
        default:
            return @"";
    }
}

+ (NSString *)returnBankName:(NSString*)idCard {
    
    if(idCard == nil || idCard.length<16 || idCard.length>19) {
        return GetBankName(WHBankNameIllegal);
    }
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"bank" ofType:@"plist"];
    NSDictionary *resultDic = [NSDictionary dictionaryWithContentsOfFile:plistPath];
    NSArray *bankBin = resultDic.allKeys;
    
    //6位Bin号
    NSString *cardbin_6 = [idCard substringWithRange:NSMakeRange(0, 6)];
    //8位Bin号
    NSString *cardbin_8 = [idCard substringWithRange:NSMakeRange(0, 8)];
    
    if ([bankBin containsObject:cardbin_6]) {
        return [resultDic objectForKey:cardbin_6];
    } else if ([bankBin containsObject:cardbin_8]) {
        return [resultDic objectForKey:cardbin_8];
    } else {
        return GetBankName(WHBankNameUnknow);
    }
}

@end
